import configparser
import logging
from Login import *

##############
#author:张子路#
##############

class GetHostConfig():
    def __init__(self):
        pass

    def GetConfig(self,CheckList):
        try:
            self.HostConfig=configparser.ConfigParser(allow_no_value=True)
            self.HostConfig.read('./setup.inf',encoding='utf-16')     #连接导出的安全策略文件
        except Exception:
            print('配置文件读取错误。')
        if len(self.HostConfig.sections())==0:
            logging.error("配置文件读取错误，请检查文件位置。", exc_info=True)
        ConfigList=[]
        try:
            for items in CheckList:
                try:
                    itemconfig=self.HostConfig.get(items[0],items[1])         #获取相应的安全策略值
                except Exception as e:
                    ConfigList.append([items[0],items[1],None])         #无设置相应安全策略时，返回当前值为None
                    #logging.error("配置提取出错 {0},错误出现于提取配置项 {1}，{2}".format(e,items[0],items[1]))
                else:
                    ConfigList.append([items[0],items[1],itemconfig])
        except Exception as e:
            logging.error("配置提取出错 {0}".format(e), exc_info=True)
        finally:
            return ConfigList        #返回相应的值

if __name__ =='__main__':
    login=LoginStart()
    login.start()
    '''g=GetHostConfig()
    CkeckList=[['Privilege Rights','SeNetworkLogonRight'],['System Access','RequireLogonToChangePassword'],['System Access','ForceLogoffWhenHourExpire']]
    c=g.GetConfig(CkeckList)
    print(c)'''

